package com.monitor.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.monitor.entity.ErpRefueling;
import com.monitor.service.ErpRefuelingService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import javax.annotation.Resource;

/**
 * <p>
 * 加油记录表 前端控制器
 * </p>
 *
 * @author LX
 * @since 2018-09-13
 */
@RestController
@RequestMapping("/erpRefueling")
@Api(description="加油记录")
public class ErpRefuelingController {

    @Resource
    private ErpRefuelingService refuelingService;


    @RequestMapping("/inertOrUpdaterefuelingId")
    @ApiOperation("添加Or修服加油记录")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> inertOrUpdaterefuelingId(ErpRefueling refueling/*,Integer custId*/)  {
        Result<Integer> result=new Result<Integer>();
        try{
            /*refueling.setCustomerId(custId);*/
        	Double total=(refueling.getRefPrice()*refueling.getRefGasoline())+(refueling.getRefPrice()*refueling.getRefDiesel());
        	refueling.setRefTotal(total);
            result.setCount(1);
            refueling.setRefTotal( refueling.getRefGasoline()+refueling.getRefDiesel());
            result.setData(refuelingService.insertOrUpdate(refueling)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getrefuelingWebById")
    @ApiOperation("根据id查看加油记录信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "refuelingId", value = "加油记录ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<ErpRefueling> getrefuelingWebById(Integer refuelingId) {
        Result<ErpRefueling> result=new Result<ErpRefueling>();
        try{
            result.setCount(1);
            result.setData(refuelingService.selectById(refuelingId));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getrefuelingIdbPage")
    @ApiOperation("根据客户ID查询加油记录")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "startTime", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "客户ID", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpRefueling>> getrefuelingIdbPage(@RequestParam(value = "startTime", defaultValue = "") String startTime,
                                                    @RequestParam(value="endTime",defaultValue="") String endTime, Integer custId) {
        Result<List<ErpRefueling>> result=refuelingService.getrefuelingId(startTime, endTime, custId);
        return result;
    }

    @RequestMapping("/removerefuelingId")
    @ApiOperation("删除加油记录信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "refuelingId", value = "加油记录ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> removeInsurance(Integer refuelingId) {
        Result<Integer>  result=new Result<Integer>();
        try{

            result.setCount(1);
            result.setData(refuelingService.deleteById(refuelingId)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

}

